﻿using Mall.Infrastructure.Model;
using Mall.Infrastructure.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sx.Mall.Domain
{
   public partial class Product
    {
        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
       public static CommonResult Add(IRepository<Product> repository, Product entity)
        {
            CommonResult result = new CommonResult();
            repository.Add(entity);
            result.IsResult = true;
            result.Message = "添加成功";
            return result;
        }


        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
       public static CommonResult Update(IRepository<Product> repository, Product entity)
        {
            CommonResult result = new CommonResult();
            var item = repository.Where(m => m.ProductID == entity.ProductID).FirstOrDefault();

            if (item != null && item.ProductID != entity.ProductID)
            {
                result.IsResult = false;
                result.Message = "产品已经存在";
            }
            else
            {
                item = repository.Where(m => m.ProductID == entity.ProductID).First();
                item.Description = entity.Description;
                item.Discount = entity.Discount;
                item.Status = entity.Status;
                item.DiscountLimit = entity.DiscountLimit;
                item.KeyWord = entity.KeyWord;
                item.price = entity.price;
                item.ProductContent = entity.ProductContent;
                item.ProductName = entity.ProductName;
                item.ProductParam = entity.ProductParam;
                item.ProductTags = entity.ProductTags;
                item.proPic = entity.proPic;
                item.smallTypeId = entity.smallTypeId;
                item.specialPrice = entity.specialPrice;
                item.specialPriceTime = entity.specialPriceTime;
                item.stock = entity.stock;
                item.bigTypeId = entity.bigTypeId;
                result.IsResult = true;
                result.Message = "更新成功";
            }
            return result;
        }


        /// <summary>
        /// 批量删除产品
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
       public static CommonResult Delete(IRepository<Product> repository, List<int> ids)
        {
            CommonResult result = new CommonResult();
            
            result.IsResult = true;
            result.Message = "删除成功";
            return result;
        }
    }
}
